<template>
  <div class="app-container">
    <!-- <div class="filter-container">
       <el-form label-width="80px">
         <el-form-item label="名字" style="width: 200px" class="filter-item">
           <el-input />
         </el-form-item>
         <el-button v-waves style="margin-left: 20px" class="filter-item" type="primary" icon="el-icon-search">
           查询
         </el-button>
         <el-button v-waves style="margin-left: 20px" class="filter-item" type="primary" icon="el-icon-search" @click="centerDialogVisible = true">
           添加
         </el-button>
       </el-form>

     </div>-->
    <el-button style="margin-left: 20px;margin-bottom: 20px" type="primary" @click="centerDialogVisible = true">
      添加
    </el-button>
    <br>
    <span>商品列表</span>
    <el-table :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="总销售量">
              <span>{{ props.row.id }}</span>
            </el-form-item>
            <el-form-item label="状态">
              <span>{{ props.row.stat }}</span>
            </el-form-item>
            <el-form-item label="描述">
              <span>{{ props.row.scrc }}</span>
            </el-form-item>
            <el-form-item label="图片">
              <el-image style="height: 60px;width: 60px" src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" />
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column align="center" label="标题">
        <template slot-scope="{row}">
          <span>{{ row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品名称">
        <template slot-scope="{row}">
          <span>{{ row.c }}</span>
        </template>
      </el-table-column>
      <el-table-column label="库存">
        <template slot-scope="{row}">
          <span>{{ row.num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="{row}">
          <span>{{ row.stat }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="{row,$index}">
          <el-link type="primary">
            修改
          </el-link>
          <el-link style="margin-left: 20px" type="primary">
            删除
          </el-link>
          <el-link v-if="row.stat!='上架'" style="margin-left: 20px" type="primary">
            上架
          </el-link>
          <el-link v-else style="margin-left: 20px" type="primary">
            下架
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="添加商品"
      :visible.sync="centerDialogVisible"
    >
      <el-form ref="form" :model="form" label-width="90px">
        <el-form-item label="商品名称">
          <el-input />
        </el-form-item>
        <el-form-item label="描述">
          <el-input />
        </el-form-item>
        <el-form-item label="图片">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
          >
            <img  v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="库存">
          <el-input />
        </el-form-item>
        <el-form-item label="积分单价">
          <el-input />
        </el-form-item>
      </el-form>
      <div style="text-align: center">
        <el-button  type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </div>

    </el-dialog>
  </div>
</template>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 80px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
<script>
import { fetchList } from '@/api/article'

export default {
  name: 'Product',
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      centerDialogVisible: false,
      list: [
        {
          id: '996',
          stat: '下架',
          title: '标题1',
          scrc: '描述1',
          c: '名称3',
          num: '1000'
        },
        {
          id: '996',
          stat: '上架',
          title: '标题2',
          c: '名称3',
          scrc: '描述2',
          num: '1000'
        },
        {
          id: '996',
          stat: '下架',
          title: '标题3',
          c: '名称3',
          scrc: '描述3',
          num: '1000'
        }
      ],
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      }
    }
  },
  methods: {

    cancelEdit(row) {
      row.title = row.originalTitle
      row.edit = false
      this.$message({
        message: 'The title has been restored to the original value',
        type: 'warning'
      })
    },
    confirmEdit(row) {
      row.edit = false
      row.originalTitle = row.title
      this.$message({
        message: 'The title has been edited',
        type: 'success'
      })
    }
  }
}
</script>

<style scoped>
  .edit-input {
    padding-right: 100px;
  }
  .cancel-btn {
    position: absolute;
    right: 15px;
    top: 10px;
  }
</style>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
